var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var ResKeeper = require("AA_ResKeeper");
var Logic_ChildMoveEvent = require("AA_Logic_ChildMoveEvent");
var BundleConfig = require("AA_BundleConfig");
var Logic_GetEquip = require("AA_Logic_GetEquip");
var UIManager = require("AA_UIManager");
var UIConfig_Game = require("AA_UIConfig_Game");
var Const_Game = require("AA_Const_Game");
var GameGlobalVariable = require("AA_GameGlobalVariable");
var CommonUtils = require("AA_CommonUtils");
var EventManager = require("AA_EventManager");
var EvenType = require("AA_EvenType");
var QiPaoTween = require("AA_QiPaoTween");
var Excel = require("AA_Excel");
var PlayerDataManager = require("AA_PlayerDataManager");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;
_decorator.inspector;
var _def_Item_GameEquip = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.node_cellFather = null;
    t.equipIcon = null;
    t.qiPaoNode = null;
    t.level5TipNode = null;
    t.level5TipLabel = null;
    t.banTouOpacity = 155;
    t.tipNode = null;
    t.unLockColor = new cc.Color(247, 41, 166);
    return t;
  }
  __extends(_creator, e);
  Object.defineProperty(_creator.prototype, "equipData", {
    get: function () {
      return this._equipData;
    },
    enumerable: false,
    configurable: true
  });
  _creator.prototype.onLoad = function () {
    var e = this;
    this._loadRes(BundleConfig.BundleNames.Game, "game/" + "res/bg/" + GameGlobalVariable.GameGlobalVariable.getSceneId(), cc.SpriteFrame).then(function (t) {
      e.node_cellFather.children.forEach(function (e) {
        e.children[0].getComponent(cc.Sprite).spriteFrame = t;
      });
    });
    this.tipNode = this.node.getChildByName("upLevel5Tip");
    this.tipNode && (this.tipNode.active = false);
  };
  _creator.prototype.onEnable = function () {
    EventManager.EventMgr.addEventListener(EvenType.EVENT_TYPE.Game_Show_Level5Tip, this.ShowTipTween, this);
  };
  _creator.prototype.onDisable = function () {
    EventManager.EventMgr.rmEventListener(EvenType.EVENT_TYPE.Game_Show_Level5Tip, this.ShowTipTween, this);
  };
  _creator.prototype.StartSet = function (e, t, o, n, i, a) {
    var r = this;
    this._equipData = e;
    this.isGeZiType = t;
    this.showPaiZi = a;
    if (!this.childMoveArray) {
      this.childMoveArray = [];
      this.node_cellFather.children.forEach(function (e) {
        var t = e.getComponent(Logic_ChildMoveEvent.default);
        t || (t = e.addComponent(Logic_ChildMoveEvent.default));
        t.StartSet(o, n, i);
        r.childMoveArray.push(t);
      });
    }
    this.ResetShow();
    this.ShowQiPao(e.isHaveQiPao);
    this.tipNode || (this.tipNode = this.node.getChildByName("upLevel5Tip"));
    this.tipNode && (this.tipNode.active = false);
  };
  _creator.prototype.ShowQiPao = function (e) {
    if (this.qiPaoNode) {
      if (e) {
        this.qiPaoNode.active = true;
        if (0 == this.qiPaoNode.childrenCount) {
          var t = this;
          this._loadRes(BundleConfig.BundleNames.Game, "game/" + "item/qiPao_" + this.equipData.pfbName, cc.Prefab).then(function (e) {
            var o = cc.instantiate(e);
            t.qiPaoNode.addChild(o);
            o.setPosition(0, 0);
            o.getComponent(QiPaoTween.default).StartSet(t.isGeZiType);
          });
        }
      } else {
        this.qiPaoNode.active = false;
      }
    }
  };
  _creator.prototype.ShowBuyView = function (e, t) {
    var o = this;
    if (this.qiPaoNode && this.qiPaoNode.active) {
      var n = this;
      var i = new Const_Game.VideoBuyOneData();
      i.furidSprite = null;
      if (this.isGeZiType) {
        i.titleStr = "额外背包格子";
        i.infoStr = "是否观看视频，获得额外的背包格子";
      } else {
        i.titleStr = "视频获得3级水果";
        i.infoStr = "是否观看视频，视频获得3级水果";
        i.furidSprite = this.equipIcon.getComponent(cc.Sprite).spriteFrame;
      }
      i.pfbName = this._equipData.pfbName;
      i.clickCallBack = function () {
        n.equipData.isHaveQiPao = false;
        o.qiPaoNode.active = false;
        o.isGeZiType && EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.ResetGameBagAI);
        t && t();
      };
      i.failCallBack = function () {
        e && e();
      };
      UIManager.default.open(BundleConfig.BundleNames.Game, UIConfig_Game.UIView_Game.UI_VideoBuyOne, i);
    } else {
      t && t();
    }
  };
  _creator.prototype.DragEndLockCell = function (e) {
    var t = this;
    this.lockCellArray = e;
    this._equipData.lockCellIndex = [];
    e && e.forEach(function (e) {
      t._equipData.lockCellIndex.push(e.cellData.cellIndex);
    });
  };
  _creator.prototype.GetGeZi = function () {
    return this.node_cellFather;
  };
  _creator.prototype.ResetShow = function () {
    this.node.getComponentInChildren(cc.Label).string = "";
    this.LoadFruitSpriteFrame();
    if (!this.equipData.lockCellIndex || 0 == this.equipData.lockCellIndex.length) {
      var e = Math.random();
      var t = 0;
      if (e > .66) {
        t = 20;
      } else {
        e < .33 && (t = -20);
      }
      this.node.angle = t;
    }
  };
  _creator.prototype.LoadFruitSpriteFrame = function () {
    return __awaiter(this, undefined, undefined, function () {
      var e;
      var t = this;
      return __generator(this, function (o) {
        switch (o.label) {
          case 0:
            e = this.equipIcon.getComponent(cc.Sprite);
            this.node_cellFather.children.forEach(function (e) {
              e.children[0].getComponent(cc.Sprite).enabled = t.equipData.equipLevel <= -1;
            });
            this.itemPaiZi || (this.itemPaiZi = this.showPaiZi(this.equipIcon));
            if (this.equipData.equipLevel <= -1) {
              e.spriteFrame = null;
              this.itemPaiZi.node.active = false;
              return [3, 3];
            } else {
              return [3, 1];
            }
          case 1:
            return [4, this._loadRes(BundleConfig.BundleNames.Common, "common/" + "res/player/" + Logic_GetEquip.default.I.GetEquipUpData(this.equipData.shuiguoId, this.equipData.equipLevel).shuiguoimg, cc.SpriteFrame).then(function (t) {
              e.spriteFrame = t;
            })];
          case 2:
            o.sent();
            this.itemPaiZi.node.active = true;
            this.itemPaiZi.StartSet(this.equipData.equipLevel, this.equipData.shuiguoId);
            o.label = 3;
          case 3:
            4 == this.equipData.equipLevel && CommonUtils.default.LoadLevel5Effect(this.equipData.shuiguoId, null, null, this._loadRes.bind(this), function (e) {
              e.parent = t.node;
              e.setPosition(0, 0);
              e.setSiblingIndex(1);
            }, function (e) {
              e.parent = t.node;
              e.setPosition(0, 0);
              e.setSiblingIndex(5);
            });
            return [2];
        }
      });
    });
  };
  _creator.prototype.SetCanClick = function (e, t) {
    undefined === t && (t = false);
    this.childMoveArray.forEach(function (t) {
      t.SetCantClick(e);
    });
    t && (this.equipIcon.opacity = e ? 255 : this.banTouOpacity);
  };
  _creator.prototype.onDestroy = function () {
    this && this.equipIcon && this.equipIcon.destroy();
  };
  _creator.prototype.ShowTipTween = function (e) {
    if (this.tipNode && this.equipData.equipLevel == GameGlobalVariable.GameGlobalVariable.normalMaxLevel - 1) {
      if (e.isShow && Logic_GetEquip.default.I.GetZaZhongId(this.equipData.shuiguoId) == e.shuiGuoId) {
        var t = Logic_GetEquip.default.I.GetMaxLevel(this.equipData.shuiguoId) == GameGlobalVariable.GameGlobalVariable.zaZhongMaxLevel || Logic_GetEquip.default.I.GetMaxLevel(e.shuiGuoId) == GameGlobalVariable.GameGlobalVariable.zaZhongMaxLevel;
        this.ShowKuangTip(t);
      } else {
        this.tipNode.stopAllActions();
        this.tipNode.active = false;
      }
    }
  };
  _creator.prototype.ShowKuangTip = function (e) {
    this.tipNode.stopAllActions();
    this.tipNode.active = true;
    this.tipNode.color = e ? this.unLockColor : cc.Color.WHITE;
    this.tipNode.children[0].active = !e;
    this.tipNode.stopAllActions();
    this.tipNode.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(.5, 1.1, 1.1), cc.scaleTo(.5, 1, 1))));
  };
  _creator.prototype.ShowUnLock5Tip = function (e, t, o) {
    if (this.level5TipNode && !this.isGeZiType && (this.level5TipNode.active = false, e && this.equipData.equipLevel == GameGlobalVariable.GameGlobalVariable.normalMaxLevel - 1)) {
      this.level5TipNode.y = this.equipIcon.height / 2;
      var n = Logic_GetEquip.default.I.GetZaZhongId(this.equipData.shuiguoId);
      var i = false;
      t.forEach(function (e) {
        e.equipData.shuiguoId == n && e.equipData.equipLevel == GameGlobalVariable.GameGlobalVariable.normalMaxLevel - 1 && (i = true);
      });
      i || o.forEach(function (e) {
        e.equipData.shuiguoId == n && e.equipData.equipLevel == GameGlobalVariable.GameGlobalVariable.normalMaxLevel - 1 && (i = true);
      });
      if (i) {
        var a = Excel.Excel.shuiguo(this.equipData.shuiguoId);
        var r = Excel.Excel.shuiguo(n);
        if (a && 0 != a.jinjieShuiGuoId && PlayerDataManager.PlayerDataMgr.GetEquipDataById(a.id).level < a.jinJieLv) {
          this.level5TipNode.active = true;
          this.level5TipLabel.string = "<color=#ffffff>" + a.name + "外围养成至</c><color=#00ff00>" + a.jinJieLv + "</c><color=#ffffff>级解锁杂交</c>";
        } else if (r && 0 != r.jinjieShuiGuoId && PlayerDataManager.PlayerDataMgr.GetEquipDataById(r.id).level < r.jinJieLv) {
          this.level5TipNode.active = true;
          this.level5TipLabel.string = "<color=#ffffff>" + r.name + "外围养成至</c><color=#00ff00>" + r.jinJieLv + "</c><color=#ffffff>级解锁杂交</c>";
        }
      }
    }
  };
  __decorate([_property(cc.Node)], _creator.prototype, "node_cellFather", undefined);
  __decorate([_property(cc.Node)], _creator.prototype, "equipIcon", undefined);
  __decorate([_property(cc.Node)], _creator.prototype, "qiPaoNode", undefined);
  __decorate([_property(cc.Node)], _creator.prototype, "level5TipNode", undefined);
  __decorate([_property(cc.RichText)], _creator.prototype, "level5TipLabel", undefined);
  return __decorate([_ccclass], _creator);
}(ResKeeper.default);
exports.default = _def_Item_GameEquip;